﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using IQKS.AWP.BusinessAccessLayer;
using IQKS.AWP.BusinessObject;
using System.Web.Services;
using System.Diagnostics;

public partial class home_CandidateAccrediationDetails : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadBindData(sender);

        }
    }

    private void LoadBindData(object sender)
    {
        ActivityMasterBAL objActMstBAL = new ActivityMasterBAL();

        DataSet objjActMstDs = new DataSet();
        objjActMstDs = objActMstBAL.GetCountryMasterActive();
        objjActMstDs=objActMstBAL.GetRegionMasterActive();

        CommonUtility.BindDropDown(ref ddlRegionSelect, objjActMstDs, "RegionName", "RegionID");
        CommonUtility.AddSelectAllToDropDownAsEmptyValue(ref ddlRegionSelect);

        //brijal added as on 16-11-2017 for RD login Region Lock
        string s = CommonUtility.GetCurrentUserRole();
        if (s == "RD")
        {
            Guid i = CommonUtility.GetLoggedOnUserId();
            DataSet ds = new UserMasterBAL().GetUserDetails(i);
            if (ds.Tables.Count > 0)
            {
                int UserRegionId = Convert.ToInt16(ds.Tables[1].Rows[0]["RegionId"]);
                if (UserRegionId > 0)
                {
                    ddlRegionSelect.SelectedValue = UserRegionId.ToString();
                    ddlRegionSelect.Enabled = false;
                }
            }
        }

        ddlRegionSelect_SelectedIndexChanged(sender, null);
    }
    protected void BtnSearch_OnClick(object sender, EventArgs e)
    {
        BindAccrediatedGv();
    }

    private void BindAccrediatedGv()
    {

        int countryID = 0;
        int regionID = Convert.ToInt32(ddlRegionSelect.SelectedValue);
        

        countryID = Convert.ToInt32(ddlCountrySelect.SelectedValue);
        DataSet objds = GetAccrediationApprovedCandidates(regionID, countryID);

        gvStatusDashboard.DataSource = objds;
        gvStatusDashboard.DataBind();
    }

    private DataSet GetAccrediationApprovedCandidates(int regionID,int countryID)
    {
        DataSet objDs = new DataSet();
        try
        {
            objDs = new CandidateDetailsBAL().GetAccrediationCompletedCandidates(regionID,countryID);
        }
        catch (Exception exception)
        {
            exception.AddErrorToLog(); //throw new ApplicationException(exception.Message);
        }
        return objDs;
    
    }
   
    protected void ddlRegionSelect_SelectedIndexChanged(object sender, EventArgs e)
    {
        GetCountryFromRegionData(Convert.ToInt64(ddlRegionSelect.SelectedValue));
    }

    private void GetCountryFromRegionData(long index)
    {
        ddlCountrySelect.DataSource = GetCountryFromRegionDataSet(index);
        ddlCountrySelect.DataTextField = "CountryName";
        ddlCountrySelect.DataValueField = "CountryID";
        ddlCountrySelect.DataBind();
        CommonUtility.AddSelectAllToDropDownAsEmptyValue(ref ddlCountrySelect);
    }
    private DataSet GetCountryFromRegionDataSet(long regionid)
    {
        DataSet objDs=null;
        try
        {
            objDs = new ActivityMasterBAL().GetCountryFromRegionMaster(regionid);
        }
        catch (Exception exception)
        {
            exception.AddErrorToLog();// throw new ApplicationException(exception.Message);
        }
        return objDs;

    }

    public string GetCertificateUrl(object objCandidateID)
    {
        string strPath = string.Empty;
        strPath = "~/Candidate/AccreditationCandidateCertificatePDF.aspx?CandidateID=" + Convert.ToString(objCandidateID);

        return strPath;
    }


    protected void gvStatusDashboard_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gvStatusDashboard.PageIndex = e.NewPageIndex;

        BindAccrediatedGv();

    }

    public string GetViewtUrl(object objCandidateID)
    {
        string strPath = string.Empty;
        strPath = "~/home/CandidateDetailsReg.aspx?CandidateID=" + CommonUtility.Encrypt(Convert.ToString(objCandidateID),true);

        return strPath;
    }
}